from bs4 import BeautifulSoup

soup = BeautifulSoup('<b class="italy boldest">Extremely bold</b>','lxml')
tag = soup.b
print(type(tag))
# 每个tag都有自己的名字,通过 .name 来获取
print(tag.name)
# 如果改变了tag的name,那将影响所有通过当前Beautiful Soup对象生成的HTML文档:
tag.name = "blockquote"
print(tag)
# 一个tag可能有很多个属性. tag <b class="boldest">
# 有一个 “class” 的属性,值为 “boldest” . tag的属性的操作方法与字典相同:
print(tag['class'])
# 可以直接”点”取属性, 比如: .attrs
print(tag.attrs)
for k,v in tag.attrs.items():
    print(k)
    print(v[0])
# tag的属性可以被添加,删除或修改. 再说一次, tag的属性操作方法与字典一样
tag['class'] = 'verybold'
tag['id'] = 1
print(tag)
del tag['class']
del tag['id']
print(tag)
# tag['class']
# KeyError: 'class'
print(tag.get('class')) # None
# html_doc = """
# <html><head><title>The Dormouse's story</title></head>
#
# <p class="title"><b>The Dormouse's story</b></p>
#
# <p class="story">Once upon a time there were three little sisters; and their names were
# <a href="http://example.com/elsie" class="sister" id="link1">Elsie</a>,
# <a href="http://example.com/lacie" class="sister" id="link2">Lacie</a> and
# <a href="http://example.com/tillie" class="sister" id="link3">Tillie</a>;
# and they lived at the bottom of a well.</p>
#
# <p class="story">...</p>
# """
# soup = BeautifulSoup(html_doc,'lxml')
# tag = soup.body.b
# print(tag)
# print(type(tag))

